<!--
 * @Author: xuxu12138 1718324422@qq.com
 * @Date: 2024-07-04 16:52:16
 * @LastEditors: xuxu12138 1718324422@qq.com
 * @LastEditTime: 2024-09-04 17:13:15
 * @FilePath: /things-admin/src/view/device/Edit/brainwave/BrainWave.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div>
    <div class="header">
      <!-- <Button
        style="margin-right: 10px"
        type="primary"
        icon="md-add"
        >添加数据</Button
      >
      <Input v-model="id" type="text" placeholder="请输入id" /> -->
      <!-- <Button
        type="primary"
        icon="ios-search"
        style="margin-right: 10px"
        size="default"
        @click="searchData"
        >查询
      </Button> -->
    </div>
    <div class="content" style="margin-top: 20px;">
      <Table border :columns="columns" highlight-row :data="data">
        <template slot-scope="{ row }" slot="action">
          <div style="white-space: nowrap">
            <Button size="small" @click="goDetail(row)" type="warning"
              >详情
            </Button>
          </div>
        </template>
      </Table>
      <div
        style="display: flex;justify-content: space-between;margin-top: 20px;"
      >
        <div></div>
        <Page :total="total" show-sizer @on-change="changeSizeValue"/>
      </div>
    </div>
  </div>
</template>

<script>
import { brainwaveFetch } from "@/base/api/Brainwave";
export default {
  data() {
    return {
      form: {
        upgradeType: "" // 更新类型
      },
      total: 0,
      data: [],
      pageIndex: 1,
      pageSize: 10,
      columns: [
        // {
        //   title: "ID",
        //   key: "id",
        //   width: 150,
        //   tooltip: true
        // },

        // {
        //   title: "会员id",
        //   key: "memberId",
        //   width: 150,
        //   tooltip: true
        // },
        {
          title: "模式名称",
          key: "autoModeName",
          tooltip: true
        },
        {
          title: "设备序列号",
          key: "deviceSn",
          tooltip: true
        },

        {
          title: "自动程序指令",
          key: "autoMode",
          tooltip: true
        },
        {
          title: "按摩手法",
          key: "autoModeName",
          tooltip: true
        },
        {
          title: "专注度前",
          key: "focusStart",
          tooltip: true
        },
        {
          title: "专注度后",
          key: "focusEnd",
          tooltip: true
        },
        {
          title: "放松前",
          key: "relaxStart",
          tooltip: true
        },
        {
          title: "放松后",
          key: "relaxEnd",
          tooltip: true
        },
        {
          title: "放松评分",
          key: "focusScore",
          tooltip: true
        },
        {
          title: "开始时间",
          key: "startTime",
          tooltip: true
        },
        {
          title: "结束时间",
          key: "endTime",
          tooltip: true
        },
        // {
        //   title: "创建时间",
        //   key: "created",
        //   width: 180,
        //   tooltip: true
        // },
        {
          title: "操作",
          key: "action",
          align: "center",
          slot: "action",
          width: 47 * 2,
          fixed: "right"
        }
      ]
    };
  },
  mounted() {
    this.brainwaveFetch();
  },
  methods: {
    // 分页
    changeSizeValue(value) {
      this.pageIndex = value;
      this.brainwaveFetch();
    },
    // 查询接口
    searchData() {},
    // 编辑
    EditItem(row) {},
    // 跳转脑波详情页
    goDetail(row) {
      this.$router.push({path:'/brainwave/detail',query:{id:row.id}})
    },
    AddBrain() {
      this.$router.push("/addbrain");
    },
    // 时间戳转化
    timestampToDateTime(timestamp) {
      var date = new Date(timestamp);
      var year = date.getFullYear();
      var month = date.getMonth() + 1;

      var day = date.getDate();
      var hour = date.getHours();
      var minute = date.getMinutes();
      var second = date.getSeconds();
      month = month < 10 ? "0" + month : month;
      day = day < 10 ? "0" + day : day;
      hour = hour < 10 ? "0" + hour : hour;
      minute = minute < 10 ? "0" + minute : minute;
      second = second < 10 ? "0" + second : second;
      return (
        year +
        "-" +
        month +
        "-" +
        day +
        " " +
        hour +
        ":" +
        minute +
        ":" +
        second
      );
    },
    // 查询脑波接口数据
    brainwaveFetch() {
      this.data = []
      let params = {
        pageIndex: this.pageIndex,
        pageSize: this.pageSize
      };
      brainwaveFetch(params).then(res => {
        this.total = res.data.itemCount;
        res.data.items.forEach(item => {
          item.startTime = this.timestampToDateTime(item.startTime);
          item.endTime = this.timestampToDateTime(item.endTime);
        });
        // this.data = res.data.items.reverse();
        res.data.items.forEach(item=>{
          this.data.push(item)
        })
      });
    }
  }
};
</script>

<style lang="less" scoped>
.header {
  display: flex;
  flex-wrap: wrap;
}
</style>
